package com.ddwl.order.controller;

import com.ddwl.common.annotation.Auth;
import com.ddwl.common.constant.BaseEnum;
import com.ddwl.common.controller.BaseController;
import com.ddwl.schema.bo.order.*;
import com.ddwl.order.service.OrderAddressServer;
import com.ddwl.order.service.OrderInfoServer;
import com.ddwl.schema.bo.base.PageBo;
import com.ddwl.schema.vo.base.PageVo;
import com.ddwl.schema.vo.base.RestVo;
import com.ddwl.schema.vo.order.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.util.List;

/**
 * 类ConsoleOrderController.java的实现描述：管理后台操作订单
 *
 * @author zach
 * @Date :2020-06-16 11:23.
 */
@Api(tags = "后台订单操作相关接口")
@RestController
public class ConsoleOrderController extends BaseController {
    

    @Resource
    private OrderInfoServer orderInfoServer;
    @Resource
    private OrderAddressServer orderAddresServer;



    @PostMapping("/page")
    @Auth(product = {BaseEnum.ProductEnum.CONSOLE})
    @ApiOperation("平台查询订单列表")
    public RestVo<PageVo<OrderInfoListVo>> page(@Valid @RequestBody PageBo<QueryOrderListBo> pageBo) {
        return RestVo.ok(orderInfoServer.getPage(pageBo));
    }

    @GetMapping("/shopData/{shopId}")
    @Auth(product = {BaseEnum.ProductEnum.API})
    @ApiOperation("店铺首页数据统计")
    public RestVo<ShopOrderDataVo> getShopData(@PathVariable("shopId") String shopId) {
        return RestVo.ok(orderInfoServer.getShopData(shopId));
    }


    @PostMapping("/delivery/list")
    @Auth(product = {BaseEnum.ProductEnum.CONSOLE, BaseEnum.ProductEnum.MALL,BaseEnum.ProductEnum.WBM, BaseEnum.ProductEnum.WBM_OFFICE, BaseEnum.ProductEnum.BYTE_DANCE, BaseEnum.ProductEnum.FENXIAO})
    @ApiOperation("查询订单发货列表")
    public RestVo<PageVo<OrderAddrVo>> delivery(@Valid @RequestBody PageBo<QueryOrderAdderListBo> bo) {
        return RestVo.ok(orderAddresServer.getPage(bo));
    }


    @PostMapping("/delivery")
    @Auth(product = {BaseEnum.ProductEnum.CONSOLE})
    @ApiOperation("订单发货")
    public RestVo delivery(@Valid @RequestBody OrderDeliveryBo bo) {
        orderInfoServer.orderDelivery(bo);
        return RestVo.ok();
    }

    @PostMapping("/orderDeliveryBySpu")
    @Auth(product = {BaseEnum.ProductEnum.CONSOLE})
    @ApiOperation("订单发货(按商品)")
    public RestVo orderDeliveryBySpu(@Valid @RequestBody OrderDeliveryBo bo) {
        orderInfoServer.orderDeliveryBySpu(bo);
        return RestVo.ok();
    }

    @PostMapping("/update/remark")
    @Auth(product = {BaseEnum.ProductEnum.CONSOLE})
    @ApiOperation("修改备注")
    public RestVo updateRemark(@Valid @RequestBody OrderUpdateBo bo) {
        orderInfoServer.updateRemark(bo);
        return RestVo.ok();
    }

    @PostMapping("/update/orderAddr")
    @Auth(product = {BaseEnum.ProductEnum.CONSOLE})
    @ApiOperation("修改地址")
    public RestVo updateAddr(@Valid @RequestBody OrderUpdateBo bo) {
        orderInfoServer.updateAddr(bo);
        return RestVo.ok();
    }

    @GetMapping("/detail")
    @Auth(product = {BaseEnum.ProductEnum.CONSOLE})
    @ApiOperation("后台订单详情")
    public RestVo<OrderDetailVo> detail(@RequestParam String id) {
        return RestVo.ok(orderInfoServer.getOrderDetail(id));
    }



    @PostMapping("/exportOrderList")
    @Auth(product = {BaseEnum.ProductEnum.CONSOLE})
    @ApiOperation("后台订单导出")
    public void exportOrderList(HttpServletResponse response, @RequestBody QueryOrderListBo bo) throws Exception {
        orderInfoServer.exportOrderList(bo,response);
    }

    @GetMapping("/getOrderAddr")
    @Auth(product = {BaseEnum.ProductEnum.CONSOLE})
    @ApiOperation("查询订单收货信息")
    public RestVo<OrderAddrVo> getOrderAddr(@RequestParam(name="orderId") String orderId) {
        return RestVo.ok(orderAddresServer.getOrderAddr(orderId));
    }


    @PostMapping("/confirmOrder")
    @Auth(product = {BaseEnum.ProductEnum.CONSOLE})
    @ApiOperation("核销自提订单")
    public RestVo confirmOrder(@Valid @RequestBody ShopConfirmOrderBo confirmOrderBo) {
        orderInfoServer.confirmOrder(confirmOrderBo);
        return RestVo.ok();
    }


    @GetMapping("/getLogisticsList")
    @ApiOperation("获取物流列表")
    public RestVo<List<LogisticsVo>> getLogisticsList() {
        List<LogisticsVo> logisticsList = orderInfoServer.getLogisticsList();
        return RestVo.ok(logisticsList);
    }


}
